Skip to content

[2/n] [ls-apis] return walked dependencies instead of using a callback#10458

Merged
sunshowers merged 2 commits into
mainfrom
sunshowers/spr/2n-ls-apis-return-walked-dependencies-instead-of-using-a-callback
May 28, 2026
Merged

[2/n] [ls-apis] return walked dependencies instead of using a callback#10458
sunshowers merged 2 commits into
mainfrom
sunshowers/spr/2n-ls-apis-return-walked-dependencies-instead-of-using-a-callback

Conversation

@sunshowers
Copy link
Copy Markdown
Contributor

@sunshowers sunshowers commented May 18, 2026

We're going to return more data from this function (the set of omitted nodes that were seen) in an upcoming PR.

I tried out a few different approaches:

  • two callbacks
  • a trait
  • a hybrid approach where we keep the current callback and return the additional data as a value

Based on the prototyping I feel like this ends up being the cleanest approach.

There are no functional changes in this PR.

Best reviewed in conjunction with its dependent PR:

Created using spr 1.3.6-beta.1
Comment thread dev-tools/ls-apis/src/cargo.rs Outdated
/// that package.
///
/// A package reachable by more than one path appears once per path.
pub found: Vec<(&'a Package, DepPath)>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make this something like a BTreeMap<&'a Package, Vec<DepPath>>? I didn't feel like it made much of a difference either way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A package reachable by more than one path appears once per path.

Nothing would happen if we had a bug where these were duplicated by mistake? If not, then I don't see a specific need to use BTreeMap<&'a Package, Vec<DepPath>>.

I'm guessing we're optimising for performance here? If that's the case, maybe a little comment explaining that would be nice.

Copy link
Copy Markdown
Contributor Author

@sunshowers sunshowers May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I actually did consider using BTreeMap<&'a Package, Vec<DepPath>> here. But I decided not to mostly to be as close to the original code as possible (which was semantically equal to returning a Vec). I could go either way on this, and certainly the BTreeMap expresses the intent a bit clearer.

Perf isn't an issue here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'll do one better and use an IdOrdMap to be even clearer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I forgot that we need to index by the package ID. Makes the case for IdOrdMap even stronger.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fwiw the reason against doing this would be to preserve DFS order -- that is not actually a concern here, since none of our use cases depend on the depth-first nature of the search. So I think this is an improvement. But if we did need to preserve the order, a Vec would be the right data structure.)

@karencfv karencfv self-requested a review May 26, 2026 20:35
Copy link
Copy Markdown
Contributor

@karencfv karencfv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for separating this out from the other PR. I have a minor question, but otherwise looks good!

Comment thread dev-tools/ls-apis/src/cargo.rs Outdated
/// that package.
///
/// A package reachable by more than one path appears once per path.
pub found: Vec<(&'a Package, DepPath)>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A package reachable by more than one path appears once per path.

Nothing would happen if we had a bug where these were duplicated by mistake? If not, then I don't see a specific need to use BTreeMap<&'a Package, Vec<DepPath>>.

I'm guessing we're optimising for performance here? If that's the case, maybe a little comment explaining that would be nice.

Created using spr 1.3.6-beta.1
Copy link
Copy Markdown
Contributor

@karencfv karencfv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thanks!

@sunshowers sunshowers merged commit bca885a into main May 28, 2026
18 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/2n-ls-apis-return-walked-dependencies-instead-of-using-a-callback branch May 28, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants